home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / dice-3.16.lha / examples / TTXSame / DError.c < prev    next >
C/C++ Source or Header  |  1998-09-27  |  34KB  |  1,197 lines

  1. //***********************************************************************
  2. //*  Copyright (c) 1993, 1994 Obvious Implementation Corp.              *
  3. //*                           All Rights Reserved.                      *
  4. //*                     207 Livingstone Drive,                          *
  5. //*                     Cary N.C. 27513 - USA                           *
  6. //***********************************************************************
  7.  
  8. #include <stdio.h>
  9. #include <exec/types.h>
  10. #include <proto/exec.h>
  11. #include <proto/dos.h>
  12. #include <dos/dos.h>
  13. #include <dos/dosextens.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <clib/exec_protos.h>
  17. #include <lib/rexx.h>
  18. #include <lib/misc.h>
  19.  
  20. #include "DError_rev.h"
  21.  
  22. #define PORTNAME "DICE_ERROR_PARSER"  // This is what everyone else calls us by
  23.  
  24. extern __stkargs LONG SetRexxVar(struct RexxMsg *,char *,char *,ULONG);
  25.  
  26. struct ErrorInfo {
  27.     struct ErrorInfo *next;      // Next error line in the list
  28.     struct ErrorInfo *prev;      // Previous line in the list
  29.     char             line[1];    // Text of the line.  Note the [1] for the NULL
  30. };
  31.  
  32. struct FileInfo {
  33.     struct FileInfo *next;       // Next file entry in the list
  34.     struct FileInfo *prev;       // Previous file entry in the list
  35.     char            *source;     // Source file that was compiled
  36.     char            *dir;        // Directory the file was compiled in
  37.     char            *args;       // Rexx arguments used for the compile
  38.     struct ErrorInfo base;       // Root node for all lines
  39.     struct ErrorInfo *cur;       // Current active error line
  40. };
  41.  
  42. struct FileInfo files;           // Root node for all files
  43. struct FileInfo *curfile;        // Current active error file
  44.  
  45. char *RexxHostName = NULL;       // We will create the host ourseleves
  46.  
  47. #define MAX_FILENAME 1024
  48. char buf[MAX_FILENAME+1];
  49. char ebuf[512];             // AREXX return string holding buffer
  50.  
  51. short run_arexx_server;
  52.  
  53. //***************************************************************************
  54. //* Procedure: AddLine                                                      *
  55. //* Synopsis:  AddLine(FileInfo *, char *)                                  *
  56. //* Purpose:   Adds the line to the current file information.  If there is  *
  57. //*            not enough memory, it will simply ignore the line silently.  *
  58. //***************************************************************************
  59. void AddLine(struct FileInfo *fi, char *line)
  60. {
  61.    struct ErrorInfo *ei;
  62.  
  63.    ei = malloc(sizeof(struct ErrorInfo) + strlen(line));
  64.    if (ei)
  65.    {
  66.       ei->prev = fi->base.prev;
  67.       ei->next = fi->base.prev->next;
  68.       strcpy(ei->line, line);
  69.       fi->base.prev->next = ei;
  70.       fi->base.prev = ei;
  71.    }
  72. }
  73.  
  74. //******************************************************************************
  75. //* Procedure: NewFile
  76. //* Synopsis:  FileInfo = NewFile(char *source, char *dir, char *args)
  77. //* Purpose:   Creates a new file info.  If it is unable to, it returns NULL
  78. //******************************************************************************
  79. struct FileInfo *NewFile(char *source, char *dir, char *args)
  80. {
  81.    struct FileInfo *fi;
  82.  
  83.    fi = malloc(sizeof(struct FileInfo));
  84.    if (fi)
  85.    {
  86.       fi->source = strdup(source);
  87.       fi->dir = strdup(dir);
  88.       fi->args = strdup(args);
  89.       fi->cur  = NULL;
  90.       if (fi->source != NULL &&
  91.           fi->dir    != NULL &&
  92.           fi->args   != NULL)
  93.       {
  94.           fi->prev = files.prev;
  95.           fi->next = files.prev->next;
  96.           files.prev->next = fi;
  97.           files.prev = fi;
  98.  
  99.           fi->base.prev = fi->base.next = &fi->base;
  100.       }
  101.       else
  102.       {
  103.          if (fi->source) free(fi->source);
  104.          if (fi->dir)    free(fi->dir);
  105.          if (fi->args)   free(fi->args);
  106.          free(fi);
  107.          fi = NULL;
  108.       }
  109.    }
  110.    return(fi);
  111. }
  112.  
  113. //************************************************************************
  114. //* Procedure: FreeFile
  115. //* Synopsis:  FreeFile(struct FileInfo *)
  116. //* Purpose:   Removes a FileInfo structure from the list
  117. //************************************************************************
  118. void FreeFile(struct FileInfo *fi)
  119. {
  120.    struct ErrorInfo *ei;
  121.  
  122.    //
  123.    // Handle any attempts to free the base FI
  124.    //
  125.    if (fi == &files) return;
  126.  
  127.    // Unlink us from the chain of file handles
  128.    fi->prev->next = fi->next;
  129.    fi->next->prev = fi->prev;
  130.  
  131.    //
  132.    // Update any system pointers which might look at what we are going to free
  133.    //
  134.    if (curfile == fi)
  135.    {
  136.       curfile = NULL;  // no more anyway
  137.    }
  138.  
  139.    //
  140.    // Free all the lines
  141.    //
  142.    fi->base.prev->next = NULL;  // mark our stopping point
  143.    for(ei = fi->base.next; ei != NULL;)
  144.    {
  145.       struct ErrorInfo *sei;
  146.  
  147.       sei = ei;
  148.       ei = ei->next;
  149.       free(sei);
  150.    }
  151.  
  152.    //
  153.    // Finally, get rid of the file information
  154.    //
  155.    free(fi->source);
  156.    free(fi->dir);
  157.    free(fi->args);
  158.    free(fi);
  159. }
  160.  
  161. //***********************************************************************
  162. //* Procedure: say
  163. //* Synopsis:  (void)say(msg);
  164. //* Purpose:   Displays the given message on the console
  165. //***********************************************************************
  166. void say(char *msg)
  167. {
  168.    BPTR out;
  169.    out = Output();
  170.    if (out)
  171.    {
  172.       Write(out, msg, strlen(msg));
  173.       Write(out, "\n", 1);
  174.    }
  175. }
  176.  
  177. //***********************************************************************
  178. //* Procedure: usage
  179. //* Synopsis:  (void)usage();
  180. //* Purpose:   Displays the command line usage message - does not return
  181. //***********************************************************************
  182. void usage(void)
  183. {
  184.    say("FILE/M,MACRO/K,PROJECT/K,REXXSTARTUP/S" VERSTAG);
  185.    exit(20);
  186. }
  187.  
  188. //***********************************************************************
  189. //* Procedure: dottx
  190. //* Synopsis:  result = dottx(port, cmd);
  191. //* Purpose:   Sends a command to TurboText
  192. //***********************************************************************
  193. char *dottx(char *port, char *cmd)
  194. {
  195.    char *res;
  196.    long ec;
  197.  
  198.    if (port == NULL) port = "TURBOTEXT";
  199.    PlaceRexxCommandDirect(NULL, port, cmd, &res, &ec);
  200.  
  201.    return(res);
  202. }
  203.  
  204. //***********************************************************************
  205. //* Procedure: full_path
  206. //* Synopsis:  path = full_path(name)
  207. //* Purpose:   Constructs a fully expanded filename
  208. //*            Note, we can not assume that the file exists, so it will
  209. //*            not be possible to actually lock it.  We can assume that
  210. //*            the directory it is part of does exist.  Note that it can
  211. //*            return NULL if there is no memory available.
  212. //***********************************************************************
  213. char *full_path(char *name)
  214. {
  215.    BPTR lock;
  216.    __aligned struct FileInfoBlock fib;
  217.    char *tail, *p;
  218.    int pos;
  219.  
  220.    //
  221.    // Step 1 - split out any directory information from the actual name
  222.    //
  223.    p = strrchr(name, '/');
  224.    if (p == NULL) p = strrchr(name, ':');
  225.    if (p != NULL)
  226.    {
  227.       //
  228.       // There was some directory information involved
  229.       //
  230.       char c;
  231.       tail = strdup(p+1);
  232.       c = p[1];
  233.       p[1] = 0;
  234.       lock = Lock(name, SHARED_LOCK);
  235.       p[1] = c;
  236.    }
  237.    else
  238.    {
  239.       //
  240.       // No directory information involved, just the name relative to the
  241.       // current directory
  242.       //
  243.       lock = Lock("", SHARED_LOCK);
  244.       tail = strdup(name);
  245.    }
  246.  
  247.    //
  248.    // Step 2 - we have the lock on the directory and the tail part of the name
  249.    // We want to construct a fully qualified path for the directory.
  250.    // If for some reason the lock on the directory returned 0, we want to just
  251.    // return the name they gave us to begin with.
  252.    //
  253.    if (lock == 0)
  254.    {
  255.       free(tail);
  256.       return(strdup(name));
  257.    }
  258.  
  259.    //
  260.    // Step 3 - Fully qualify the directory portion into the buffer
  261.    //
  262.    if (DOSBase->dl_lib.lib_Version >= 36)
  263.    {
  264.       if (!NameFromLock(lock, buf, MAX_FILENAME))
  265.       {
  266.          //
  267.          // Either the name is too long or there was something else wrong with
  268.          // the file name, just return what they gave us as a start
  269.          //
  270.          UnLock(lock);
  271.          free(tail);
  272.          return(strdup(name));
  273.       }
  274.       UnLock(lock);
  275.       pos = 0;
  276.    }
  277.    else
  278.    {
  279.       // Running under